home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1997 July
/
macformat52.iso
/
mac
/
Shareware Plus
/
Developers
/
YAAF v1.0 alpha 1
/
(Sources)
/
Standard Controls
/
Buttons
/
XGStdButton.cpp
next >
Wrap
Text File
|
1997-04-24
|
8KB
|
400 lines
/* XGStdButton.cpp
*
* This puts up a standard push button. This uses the standard
* OS push button if it is available
*/
/* YAAF - Yet another application framework
* Copyright (C) 1997 William Edward Woody and In Phase Consulting
*
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Library
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or any
* later version.
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Library General Public License for
* more details.
*
* You should have received a copy of the GNU Library General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* To contact the author, either e-mail me at
* woody@alumni.caltech.edu, or write to us at
*
* William Edward Woody
* In Phase Consulting
* 1545 Ard Eevin Avenue
* Glendale, CA 91202
*/
#include <XDataUtil.h>
#include <XStdButtons.h>
#include <XWindow.h>
#include <XError.h>
/************************************************************************/
/* */
/* Construction/Destruction */
/* */
/************************************************************************/
/* XGStdButton::XGStdButton
*
* create a push button
*/
XGStdButton::XGStdButton(XGView *view, XGArgStream &stream, bool f) :
XGView(view,stream,f)
{
#if OPT_MACOS == 1
fControl = NULL;
#endif
}
XGStdButton::XGStdButton(XGView *view, XGSViewInitRecord &i, bool f) :
XGView(view,i,f)
{
#if OPT_MACOS == 1
fControl = NULL;
#endif
}
/* XGStdButton::~XGStdButton
*
* Delete me
*/
XGStdButton::~XGStdButton()
{
#if OPT_MACOS == 1
if (fControl) ::DisposeControl(fControl);
#endif
}
/************************************************************************/
/* */
/* Control management */
/* */
/************************************************************************/
/* XGStdButton::DoDrawView
*
* Draw my control. This draws the control in a wierd way.
*/
void XGStdButton::DoDrawView(Rect)
{
#if OPT_MACOS == 1
XGDraw draw(this,false);
::TextFont(fFont);
::TextSize(fSize);
if (fControl) ::Draw1Control(fControl);
#endif
}
/* XGStdButton::DoActivate
*
* Handle activation/deactivation
*/
void XGStdButton::DoActivate(bool active)
{
#if OPT_MACOS == 1
XGDraw draw(this,false);
::TextFont(fFont);
::TextSize(fSize);
if (fControl && IsEnabled()) {
if (active) ::HiliteControl(fControl,0);
else ::HiliteControl(fControl,255);
}
#endif
#if OPT_WINOS == 1
#pragma unused(active)
#endif
}
/* XGStdButton::DoMouseDown
*
* Handle mouse click
*/
bool XGStdButton::DoMouseDown(Point pt, short)
{
#if OPT_MACOS == 1
short i;
if (!fControl) return false;
{
XGDraw draw(this,false);
::TextFont(fFont);
::TextSize(fSize);
ViewToGlobal(&pt);
i = ::TrackControl(fControl,pt,NULL);
}
if (i) ReceiveDispatch(KEventButton,GetViewID(),(void *)this);
#endif
#if OPT_WINOS == 1
#pragma unused(pt)
#endif
return false;
}
/* XGStdButton::DoMoveView
*
* Move this view to the new location
*/
void XGStdButton::DoMoveView(void)
{
#if OPT_MACOS == 1
XGDraw draw(this,false);
Rect r;
::TextFont(fFont);
::TextSize(fSize);
r = GetContentRect();
ViewToGlobal(&r);
if (fControl) ::MoveControl(fControl,r.left,r.top);
#endif
}
/* XGStdButton::DoSizeView
*
* This handles the resize event
*/
void XGStdButton::DoSizeView(void)
{
#if OPT_MACOS == 1
XGDraw draw(this,false);
Rect r;
::TextFont(fFont);
::TextSize(fSize);
r = GetContentRect();
ViewToGlobal(&r);
if (fControl) ::SizeControl(fControl,r.right-r.left,r.bottom-r.top);
#endif
}
/* XGStdButton::ShowView
*
* This also shows the control
*/
void XGStdButton::ShowView()
{
XGView::ShowView();
#if OPT_MACOS == 1
if (fControl) {
XGDraw draw(this,false);
::TextFont(fFont);
::TextSize(fSize);
::ShowControl(fControl);
}
#endif
}
/* XGStdButton::HideView
*
* This also hides the control
*/
void XGStdButton::HideView()
{
XGView::HideView();
#if OPT_MACOS == 1
if (fControl) {
XGDraw draw(this,false);
::TextFont(fFont);
::TextSize(fSize);
::HideControl(fControl);
}
#endif
}
/* XGStdButton::EnableView
*
* This also enables the control.
*/
void XGStdButton::EnableView()
{
XGView::EnableView();
#if OPT_MACOS == 1
if (fControl && IsActive()) {
XGDraw draw(this,false);
::TextFont(fFont);
::TextSize(fSize);
::HiliteControl(fControl,255);
}
#endif
}
/* XGStdButton::DisableView
*
* This also disables the control
*/
void XGStdButton::DisableView()
{
XGView::DisableView();
#if OPT_MACOS == 1
if (fControl && IsActive()) {
XGDraw draw(this,false);
::TextFont(fFont);
::TextSize(fSize);
::HiliteControl(fControl,0);
}
#endif
}
/************************************************************************/
/* */
/* Message Dispatch */
/* */
/************************************************************************/
/* XGStdButton::ReceiveDispatch
*
* Receive messages. Pass them upwards.
*
* On Windows, this interprets the internal message that is
* generated when a control is clicked and translates it into my
* more general purpose control messages
*/
long XGStdButton::ReceiveDispatch(long msg, long arg, void *parg)
{
#if OPT_WINOS == 1
XGSWInternalRecord *w;
if (msg == KEventWInternal) {
/*
* Process the BN_CLICKED command message, turning this
* into a KEventButton message.
*/
w = (XGSWInternalRecord *)parg;
if (w->msg == WM_COMMAND) {
short notify;
notify = HIWORD(w->wp);
if (notify == BN_CLICKED) {
ReceiveDispatch(KEventButton,GetViewID(),(void *)this);
return 0;
}
}
return 1;
}
#endif
return XGView::ReceiveDispatch(msg,arg,parg);
}
/************************************************************************/
/* */
/* Button Values */
/* */
/************************************************************************/
/* XGStdButton:GetValue
*
* Get value
*/
short XGStdButton::GetValue(void)
{
#if OPT_MACOS == 1
return ::GetControlValue(fControl);
#endif
#if OPT_WINOS == 1
int i;
i = ::SendMessage(_GetHWND(),BM_GETCHECK,0,0);
if (i == BST_CHECKED) return 1;
if (i == BST_UNCHECKED) return 0;
return 2; /* Indeterminate (tri-state) */
#endif
}
/* XGStdButton::SetValue
*
* Set the value of this thing
*/
void XGStdButton::SetValue(short x)
{
#if OPT_MACOS == 1
XGDraw draw(this,false); // make sure set up right
::TextFont(fFont);
::TextSize(fSize);
::SetControlValue(fControl,x);
#endif
#if OPT_WINOS == 1
if (x < 0) x = 0;
if (x > 2) x = 0;
::SendMessage(_GetHWND(),BM_SETCHECK,(WPARAM)x,0);
#endif
}
/* XGStdButton::GetText
*
* Get the text contents
*/
void XGStdButton::GetText(char *str)
{
#if OPT_MACOS == 1
::GetControlTitle(fControl,(unsigned char *)str);
p2cstr((unsigned char *)str);
#endif
#if OPT_WINOS == 1
::GetWindowText(_GetHWND(),str,256); // assume 256 byte buffer
#endif
}
/* XGStdButton::SetText
*
* Set the text contents of this button
*/
void XGStdButton::SetText(char *str)
{
#if OPT_MACOS == 1
XGDraw draw(this,false);
unsigned char buffer[256];
::TextFont(fFont);
::TextSize(fSize);
cvtc2p(buffer,str);
::SetControlTitle(fControl,buffer);
#endif
#if OPT_WINOS == 1
::SetWindowText(_GetHWND(),str);
#endif
}